<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style/editor.css" rel="stylesheet" type="text/css">
<script>
  var sLangDir=parent.oUtil.langDir;
  document.write("<scr"+"ipt src='language/"+sLangDir+"/bookmark.js'></scr"+"ipt>");
</script>
<script>writeTitle()</script>
<script>
/*** COMMON ***/
function GetElement(oElement,sMatchTag)
  {
  while (oElement!=null&&oElement.tagName!=sMatchTag)
    {
    if(oElement.tagName=="BODY")return null;
    oElement=oElement.parentElement;
    }
  return oElement;
  }
/*** REALTIME + PREVIEW ***/
function doWindowFocus()
  {
  parent.oUtil.onSelectionChanged=new Function("realTime()");
  updateList();
  }
function bodyOnLoad()
  {
  loadTxt();

  window.onfocus=doWindowFocus;
  parent.oUtil.onSelectionChanged=new Function("realTime()");
  updateList();
  realTime();
  }

function bodyOnUnload() {
  parent.oUtil.onSelectionChanged=null;
}

function updateList()
  {
  var oEditor=parent.oUtil.oEditor;

  while(lstBookmark.options.length!=0)
    {
    lstBookmark.options.remove(lstBookmark.options(0))
    }
  for(var i=0;i<oEditor.document.anchors.length;i++)
    {
    var op = document.createElement("OPTION");
    op.text=oEditor.document.anchors[i].name;
    op.value=oEditor.document.anchors[i].name;
    lstBookmark.options.add(op);
    }
  }
function selectBookmark(sName)
  {
  parent.oUtil.obj.setFocus();
  if(!parent.oUtil.obj.checkFocus()){return;}//Focus stuff
  var oEditor=parent.oUtil.oEditor;
  var oSel=oEditor.document.selection.createRange();
  var sType=oEditor.document.selection.type;

  oSel.execCommand("Unselect");

  for(var i=0;i<oEditor.document.anchors.length;i++)
    {
    if(oEditor.document.anchors[i].name==sName)
      {
      if(oSel.parentElement)
        {
        var oSelRange = oEditor.document.body.createTextRange()
        oSelRange.moveToElementText(oEditor.document.anchors[i])
        oSel.setEndPoint("StartToStart",oSelRange);
        oSel.setEndPoint("EndToEnd",oSelRange);
        oSel.select();
        }
      }
    }
  realTime();
  parent.realTime(parent.oUtil.oName);
  parent.oUtil.obj.selectElement(0);
  parent.oUtil.obj.bookmarkSelection();
  }
function realTime()
  {
  if(!parent.oUtil.obj.checkFocus())return;//Focus stuff
  var oEditor=parent.oUtil.oEditor;
  var oSel=oEditor.document.selection.createRange();
  var sType=oEditor.document.selection.type;

  //If text or control is selected, Get A element if any
  if (oSel.parentElement) oEl=GetElement(oSel.parentElement(),"A");
  else oEl=GetElement(oSel.item(0),"A");

  if (oEl)
    {
    btnInsert.style.display="none";
    btnApply.style.display="block";
    btnOk.style.display="block";

    if(sType!="Control")
      {
      var oEditor=parent.oUtil.oEditor;
      var oSelRange = oEditor.document.body.createTextRange()
      oSelRange.moveToElementText(oEl)
      oSel.setEndPoint("StartToStart",oSelRange);
      oSel.setEndPoint("EndToEnd",oSelRange);
      oSel.select();
      }

    if(oEl.NAME)inpName.value=oEl.NAME;
    if(oEl.name)inpName.value=oEl.name;
    }
  else
    {
    btnInsert.style.display="block";
    btnApply.style.display="none";
    btnOk.style.display="none";

    inpName.value="";
    }
  }

function doApply()
  {
  parent.oUtil.obj.setFocus();
  if(!parent.oUtil.obj.checkFocus())return;//Focus stuff
  var oEditor=parent.oUtil.oEditor;
  var oSel=oEditor.document.selection.createRange();
  var sType=oEditor.document.selection.type;

  parent.oUtil.obj.saveForUndo();

  if(inpName.value!="")
    oSel.execCommand("CreateBookmark",false,inpName.value);
  else
    oSel.execCommand("UnBookmark");

  updateList();
  realTime();

  //~~~~~~~~ Focus stuff
  var oEditor=parent.oUtil.oEditor;
  oEditor.focus()

  //*** RUNTIME STYLES ***
  var obj=parent.oUtil.obj;
  obj.runtimeStyles();
  //***********************

  parent.realTime(parent.oUtil.oName);
  parent.oUtil.obj.selectElement(0);
  parent.oUtil.obj.bookmarkSelection();
  }

function windowClose() {
  parent.oUtil.onSelectionChanged=null;
  self.closeWin();
};

</script>
</head>
<body style="overflow:hidden;">

<table width="100%" height="185px" align=center cellpadding=0 cellspacing=0>
<tr>
<td valign=top style="padding:5px;">

  <table width=100% border="0">
  <tr>
  <td width="100%">
  <select size=5 name="lstBookmark" style="width:100%" id="lstBookmark" onchange="selectBookmark(this.value);selectBookmark(this.value)" class="inpSel">
  </select>
  <td>
  </tr>
  </table><br>

  <table width=100%>
  <tr>
    <td nowrap><span id="txtLang" name="txtLang">Name</span>:</td>
    <td style="width:100%;padding-right:5px"><INPUT type="text" ID="inpName" NAME="inpName" style="width:100%" class="inpTxt"></td>
  </tr>
  </table>

</td>
</tr>
<tr>
<td class="dialogFooter" align="right">
  <table cellpadding=0 cellspacing=0>
  <tr>
  <td>
  <input type=button name=btnCancel id=btnCancel value="cancel" onclick="windowClose()" class="inpBtn" onmouseover="this.className='inpBtnOver';" onmouseout="this.className='inpBtnOut'">
  </td>
  <td>
  <input type=button name=btnInsert id=btnInsert value="insert" onclick="doApply()" class="inpBtn" onmouseover="this.className='inpBtnOver';" onmouseout="this.className='inpBtnOut'">
  </td>
  <td>
  <input type=button name=btnApply id=btnApply value="apply" style="display:none" onclick="doApply()" class="inpBtn" onmouseover="this.className='inpBtnOver';" onmouseout="this.className='inpBtnOut'">
  </td>
  <td>
  <input type=button name=btnOk id=btnOk value=" ok " style="display:none;" onclick="doApply();windowClose()" class="inpBtn" onmouseover="this.className='inpBtnOver';" onmouseout="this.className='inpBtnOut'">
  </td>
  </tr>
  </table>
</td>
</tr>
</table>

</body>
</html>